library(SDMTools)

work.dir = "I:/Barra Work Directory/2080_GCMs/sresa1b.giss_aom.run1.run1.2066.2095/"; setwd(work.dir)
out.dir = "I:/Barra Work Directory/outputs/"

pnts=cbind(x=c(112,116,116,112), y=c(-11,-11,-18.5,-18.5))
cols = colorRampPalette(c('skyblue','slateblue','forestgreen','yellow','red'))(101)


sum.temp =NULL
for (ii in 1:12) { cat(ii,'\n')
      tasc = (read.asc.gz(paste("tasmax", sprintf('%02i',ii), ".asc.gz",sep=''))+
			read.asc.gz(paste("tasmin", sprintf('%02i',ii), ".asc.gz",sep='')))/2
      if (length(sum.temp) == 0) { #if there are no values , populate it
          sum.temp = tasc
        } else { #if already has values, add the new values to it
          sum.temp = sum.temp + tasc
		 } 
}
sum.temp=sum.temp/12

#############
zlim=range(sum.temp, na.rm=T) #given what you know about zlim

png(paste(out.dir,'sum.temp.gissaom.png',sep=''), width=7, height=7, units='cm', res=300, pointsize=5, bg='white')
image(sum.temp, zlim=zlim, ann=FALSE,axes=FALSE,col=cols)


legend.gradient(pnts,cols=cols,limits=round(zlim), title='Mean. Temp.', cex=1)
  

dev.off()
#############

